<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>hello world</title>
    <script src="vue.js"></script>
</head>
<body>
<div id="app">
    <input type="text" v-model="inputValue">
    <button @click="handleClick">提交</button>
    <ul>
        <!--<li v-for="item in list">{{ item }}</li>-->
        <todo-item v-bind:content = "item"
                   v-bind:index = 'index'
                   v-for="(item,index) in list"
                    @detele = 'handleItemDel'>
        </todo-item>
    </ul>
</div>
<script>
    /*全局组件*/
    /*Vue.component('TodoItem',{
        props:['content'],
        template:"<li>{{ content }}</li>"
    });*/

    /*局部组件*/
    var TodoItem = {
        props:['content','index'],
        template:"<li @click='handleDelItem'>{{ content }}</li>",
        methods:{
            handleDelItem:function () {
                this.$emit('detele',this.index)
            }
        }
    }

    var app = new Vue({
        el:"#app",
        components:{
            TodoItem:TodoItem
        },
        data:{
            list:[],
            inputValue:""
        },
        methods:{
            handleClick:function () {
                    this.list.push(this.inputValue);
                    this.inputValue = '';
            },
            handleItemDel:function (index) {
                this.list.splice(index,1);
            }
        }
    });
</script>
</body>
</html>